//
//  LLStatusLayout.m
//  LoveLove
//
//  Created by 肖兰月 on 2019/4/2.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLStatusLayout.h"
#import "LLStatusModel.h"

#define leftMargin 15
#define bigImgViewScale 195/345
#define imgViewScale 75/113
#define verticalMargin 14

@implementation LLStatusLayout

- (void)setModel:(LLStatusModel *)model {
    _model = model;

    if ([_model.is_poster intValue] == 1) {
        _model.type = @"1000";
    }

    if (model.type.integerValue == 1) {
        if (model.newsTitle.length) {
            CGFloat contentTextH = [CommonTools sizeOfText:model.newsTitle fontSize:19 width:LLScreenWidth-2*leftMargin].height;
            _contentTextFrame = CGRectMake(leftMargin, 10, LLScreenWidth-2*leftMargin, contentTextH + 15);
        } else {
            _contentTextFrame = CGRectZero;
        }
        
        CGFloat statusInfoY = 0;
        if (model.img_url.count == 1) {
            CGFloat imgViewW = LLScreenWidth-2*leftMargin;
            NSString *imgViewFrame = NSStringFromCGRect(CGRectMake(leftMargin, CGRectGetMaxY(_contentTextFrame),imgViewW , imgViewW*bigImgViewScale));
            _imgFrames = @[imgViewFrame];
            statusInfoY = CGRectGetMaxY(_contentTextFrame) + imgViewW*bigImgViewScale + verticalMargin;
        } else if (model.img_url.count > 1) {
            NSMutableArray *imgViewFrames = NSMutableArray.new;
            CGFloat margin = 5;
            CGFloat imgViewW = (LLScreenWidth-leftMargin*2-(model.img_url.count-1)*margin)/model.img_url.count;
            CGFloat imgViewH = imgViewW * imgViewScale;
            for (NSInteger i = 0; i < model.img_url.count; i++) {
                NSString *imgViewFrame = NSStringFromCGRect(CGRectMake(leftMargin + (margin + imgViewW)*i, CGRectGetMaxY(_contentTextFrame), imgViewW, imgViewH));
                [imgViewFrames addObject:imgViewFrame];
            }
            _imgFrames = imgViewFrames;
            statusInfoY = CGRectGetMaxY(_contentTextFrame) + imgViewH + verticalMargin;
        } else {
            _imgFrames = @[];
            statusInfoY = CGRectGetMaxY(_contentTextFrame);
        }
        
        _bottomInfoFrame = CGRectMake(leftMargin, statusInfoY, LLScreenWidth-leftMargin-50, 20);
        _editBtnFrame = CGRectMake(LLScreenWidth-30-leftMargin, statusInfoY-5, 30, 30);
        _cellHeight = CGRectGetMaxY(_bottomInfoFrame) + 5;
    } else {
        NSString *imgViewFrame = NSStringFromCGRect(CGRectMake(LLScreenWidth-113-leftMargin, 10, 113, 75));
        _imgFrames = @[imgViewFrame];
        _contentTextFrame = CGRectMake(leftMargin, 10, LLScreenWidth-leftMargin*2-113-10, 75);
        _editBtnFrame = CGRectMake(LLScreenWidth-30-leftMargin, 75+10+verticalMargin, 30, 30);
        _bottomInfoFrame = CGRectMake(leftMargin, 75+10+verticalMargin+5, LLScreenWidth-leftMargin-50, 20);
        _cellHeight = CGRectGetMaxY(_bottomInfoFrame)+10;
    }
}

@end
